from rest_framework import exceptions
from api import models

class Authtication(object):
    def authenticate(self,request):
        token = request._request.GET.get('token')
        token_obj=models.userToken.objects.filter(token=token).first()
        if not token_obj:
            raise exceptions.AuthenticationFailed('用户认证失败')
        return (token_obj.user,token_obj)

    def authenticate_header(self,request):
        pass

def permission_SVIP(object):

    def has_permission(self,request,view):
        if request.user.user_type != 3:
            return False
        return True

def permission_VIP(object):

    def has_permission(self,request,view):
        if request.user.user_type != 2:
            return False
        return True

